import { login, logout, editPassword } from "@/api/login";
import { ElMessage } from "element-plus";
import router from "@/router";
import { removeToken } from "@/utils/auth";
// 3.添加vuex参数
const state = {};

const mutations = {
  // set_login(state, data) {
  //   console.log(data);
  //   // state.userName
  // },
};

const actions = {
  logout({ commit }, query) {
    return new Promise((resolve, reject) => {
      logout(query).then((res) => {
        router.push("/login");
        ElMessage({
          message: "退出登录成功",
          type: "warning",
        });
      });
    });
  },
  editPassword({ commit }, query) {
    return new Promise((resolve, reject) => {
      editPassword(query).then((res) => {
        router.push("/login");
        removeToken();
        ElMessage({
          message: res.msg,
          type: "success",
        });
      });
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
